#coding=utf-8
import arcpy
import json

from sympy import false

arcpy.env.overwriteOutput = True
spatial_ref = arcpy.SpatialReference(4326)
with open((r'D:\WorkData\20251118甘孜河流流域面\1.json').decode('utf-8'),'rb') as file:
    content = file.read()
data = json.loads(content)
dataCount = len(data['features'])
ArcpyPolyline_List = []
for i in range(dataCount):
    if len(data['features'][i]['geometry']['data']) > 0:
        geo = json.loads(data['features'][i]['geometry']['data'][0]['geom'])['coordinates']
        if len(geo) < 2:
            coordsList_Top = json.loads(data['features'][i]['geometry']['data'][0]['geom'])['coordinates'][0]
            ly = data['features'][i]['geometry']['data'][0]['sxname']
            name = data['features'][i]['geometry']['data'][0]['rname']
            pcdm = data['features'][i]['geometry']['data'][0]['pcdm'] or 'no_data'
            area = data['features'][i]['geometry']['data'][0]['basinarea']or 'no_data'
            print i,name
            for coordsList in coordsList_Top:
                ArcpyPoint_List = [arcpy.Point(*coords) for coords in coordsList]
                ArcpyArray_List = arcpy.Array(ArcpyPoint_List)
                ArcpyPolyline = arcpy.Polygon(ArcpyArray_List, spatial_ref)
                ArcpyPolyline_List.append([ArcpyPolyline, ly,name,pcdm,area])

c_polyline = arcpy.CreateFeatureclass_management(r'D:\WorkData\20251118甘孜河流流域面'.decode('utf-8'), '1118.shp', 'POLYGON',spatial_reference=spatial_ref)
arcpy.AddField_management(c_polyline, 'ly', 'TEXT')
arcpy.AddField_management(c_polyline, 'name', 'TEXT')
arcpy.AddField_management(c_polyline, 'pcdm', 'TEXT')
arcpy.AddField_management(c_polyline, 'area', 'TEXT')
cs = arcpy.da.InsertCursor(c_polyline, ['SHAPE@', 'ly','name','pcdm','area'])
for ArcpyPolyline in ArcpyPolyline_List:
    cs.insertRow(ArcpyPolyline)
del cs